package com.cyz.web.app.listener;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * 使用ApplicationListener初始化一些数据到application对象域中的监听器
 * 实现 ApplicationListener<ContextRefreshedEvent> 接口，重写 onApplicationEvent 方法
 */
@Component
public class MyServletContextListener implements ApplicationListener<ContextRefreshedEvent> {
    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        //先获取application的上下文
        ApplicationContext applicationContext = contextRefreshedEvent.getApplicationContext();
        UserService userService = applicationContext.getBean(UserService.class);





    }
}
